{% extends "edit/edit-base.html" %} 
{% block content %}
 <table class="table table-striped">
      <thead>
        <tr>
          <th>#</th>
          <th>分类</th>
          <th>%</th>
          <th>@</th>
        </tr>
      </thead>
      <tbody>
      {% if classify_list %}
		{% for classify in classify_list %}
        <tr>
          <td>{{classify.id}}</td>
          <td>{{classify.content }}</td> 
          {% ifequal classify.id 1%}
          <td></td>
          <td></td>
          	{%else%}
          <td class="update"><input type="text" id="group_{{classify.id}}" value="{{classify.content}}" style="display:none;"/><input type="button" value="确认" id="submit_{{classify.id}}" classifyid="{{classify.id}}" style="display:none;" class="submit_update"/><input type="button" style="display:none;" value="取消" id="concel_{{classify.id}}" onclick="location.reload()" /><a href="#" classifyid="{{classify.id}}" TITLE="修改">修改</a></td>
          <td class="delete"><a href="#" id="{{classify.id}}" TITLE="删除"><img  src="/images/delete.png" height="20" width="20"></a></td>
          {%endifequal%}
        </tr>
        {% endfor%}
        {%endif%}
        <!-- -新增 -->
        <tr>
          <td>+++</td>
          <td> <input type="text" class="form-control" id="addClassify" placeholder="新建分类。。。"></td> 
			
          <td class="add"><a href="#"  TITLE="添加"><img  src="/images/add.jpg" height="20" width="20"></a></td>
       	 <td></td>
        </tr>
      </tbody>
    </table>
<script type="text/javascript">
function deleteClassify(id){
	$.post("/edit/delete_classify/", {id:id}, function (result) { 
		if(result=="success"){
		//	alert("删除成功。。。");
			window.location.href='/edit/get_classify_list';
		}
	});
}


function addClassify(content){
	$.post("/edit/add_classify/", {content:content}, function (result) { 
		if(result=="success")
			window.location.href='/edit/get_classify_list';
	});
}
$(document).ready(function(){

	//删除分类
	  $(".delete a ").click(function(){
		var id = $(this).attr("id");
		if( confirm("确认删除当前分类。。。")){
			deleteClassify(id);
		}
	  });
	
	//修改分类
	  $(".update a ").click(function(){
		var id = $(this).attr("classifyid");
		$(this).hide();
		$("#group_"+id).show();		
		$("#submit_"+id).show();
		$("#concel_"+id).show();
	  });
	
	  $(".submit_update").click(function(){
			var id = $(this).attr("classifyid");
			var content  = $("#group_"+id).val();
			$.post("/edit/update_classify/", {id:id,content:content}, function (result) { 
				if(result=="success")
					window.location.href='/edit/get_classify_list';
			});
		  });
	
	//添加分类
	  $(".add a ").click(function(){
		var content = $("#addClassify").val();
		if(content==" " || content.length==0){
			alert("未填写内容。。。");
			$("#addClassify").focus();
		}else if( confirm("确认添加当前分类。。。")){
			addClassify(content);
		}
	  });
		  
	});
</script>
{% endblock %}
